package com.ruoyi.info.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.info.domain.FhInfoMyspace;
import com.ruoyi.info.service.IFhInfoMyspaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 我的空间Controller
 *
 * @author ruoyi
 * @date 2024-11-19
 */
@RestController
@RequestMapping("/info/myspace")
public class FhInfoMyspaceController extends BaseController {
    @Autowired
    private IFhInfoMyspaceService fhInfoMyspaceService;

    /**
     * 查询我的空间列表
     */
    @PreAuthorize("@ss.hasPermi('info:myspace:list')")
    @GetMapping("/list")
    public TableDataInfo list(FhInfoMyspace fhInfoMyspace) {
        startPage();
        List<FhInfoMyspace> list = fhInfoMyspaceService.selectFhInfoMyspaceList(fhInfoMyspace);
        return getDataTable(list);
    }

    /**
     * 导出我的空间列表
     */
    @PreAuthorize("@ss.hasPermi('info:myspace:export')")
    @Log(title = "我的空间", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FhInfoMyspace fhInfoMyspace) throws IOException {
        List<FhInfoMyspace> list = fhInfoMyspaceService.selectFhInfoMyspaceList(fhInfoMyspace);
        ExcelUtil<FhInfoMyspace> util = new ExcelUtil<FhInfoMyspace>(FhInfoMyspace.class);
        util.exportExcel(response, list, "我的空间数据");
    }

    /**
     * 获取我的空间详细信息
     */
    @PreAuthorize("@ss.hasPermi('info:myspace:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(fhInfoMyspaceService.selectFhInfoMyspaceById(id));
    }

    /**
     * 新增我的空间
     */
    @PreAuthorize("@ss.hasPermi('info:myspace:add')")
    @Log(title = "我的空间", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FhInfoMyspace fhInfoMyspace) {
        return toAjax(fhInfoMyspaceService.insertFhInfoMyspace(fhInfoMyspace));
    }

    /**
     * 修改我的空间
     */
    @PreAuthorize("@ss.hasPermi('info:myspace:edit')")
    @Log(title = "我的空间", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FhInfoMyspace fhInfoMyspace) {
        return toAjax(fhInfoMyspaceService.updateFhInfoMyspace(fhInfoMyspace));
    }

    /**
     * 删除我的空间
     */
    @PreAuthorize("@ss.hasPermi('info:myspace:remove')")
    @Log(title = "我的空间", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(fhInfoMyspaceService.deleteFhInfoMyspaceByIds(ids));
    }
}
